package tool.codescan.visitors;

import tool.codescan.TypeResolver;
import tool.codescan.loggers.VariableAndParameterLogger;
import tool.data.TypeDefinition;
import japa.parser.ast.body.FieldDeclaration;
import japa.parser.ast.visitor.VoidVisitorAdapter;

	/**
	 * @author jwb09119
	 * @date 2013/11/22
	 * 
	 * This visitor visits class variables.
	 */

public class VariableVisitor<A> extends VoidVisitorAdapter<A>{

	private VariableAndParameterLogger storage;
	private IVisitorContext parent;
	
	public VariableVisitor(VariableAndParameterLogger logger, IVisitorContext parent) {
		
		storage = logger;
		this.parent = parent;
		
	}
	
	
    @Override
    public void visit(FieldDeclaration n, A arg) {
    	//System.out.println("\nVariable Declaration: \n" + n.toString());
    	
    	String name = n.getVariables().get(0).getId().getName();
    	String typeName = TypeResolver.getTypeName(n.getType());
    	TypeDefinition fullTypeName = parent.getFullTypeAddress(typeName);
    	boolean isArray = (n.getVariables().get(0).getId().getArrayCount() > 0);
    	int modifiers = n.getModifiers();
    	
    	storage.registerClassVariable(name, fullTypeName, isArray, modifiers);

    }
     
	
}
